package com.hazardSoft.eStore.integration;

import java.util.List;

import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.common.integration.EJB3ServiceLocator;
import com.hazardSoft.eStore.ejb.ProductsEJB;
import com.hazardSoft.eStore.entities.Product;
import com.hazardSoft.eStore.interfaces.ProductsLocal;
import com.hazardSoft.eStore.utils.PathConstants;


public class ProductsDelegate {

	private static final String CLASS_NAME = PathConstants.DELEGATES_PATH+ProductsDelegate.class.getSimpleName();
	private ProductsLocal productsLocal;
	
	public ProductsDelegate() throws SystemException{
		
		try {
			productsLocal = (ProductsLocal) EJB3ServiceLocator.getLocalEJB(ProductsEJB.EJB_NAME);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "ProductsDelegate");
		}
	}
	
	public Product insertProduct(Product product) throws SystemException {
		
	
		try {
			return productsLocal.insertProduct(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "insertProduct");
		}
	}

	
	public List<Product> listProducts() throws SystemException {
		
		try {
			return productsLocal.listProducts();
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "listProducts");
		}
	}

	
	public boolean removeProduct(Product product) throws SystemException {
		
		try {
			return productsLocal.removeProduct(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "removeProducts");
		}
	}

	
	public Product searchProductbyId(Product product) throws SystemException {
		
		try {
			return productsLocal.searchProductbyId(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "searchProductById");
		}
	}

	
	public Product searchProductbyName(Product product) throws SystemException {
	
		try {
			return productsLocal.searchProductbyName(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "searchProductByName");
		}
	}

	
	public Product updateProduct(Product product) throws SystemException {
		
		try {
			return productsLocal.updateProduct(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "updateProduct");
		}
	}

	public List<Product> searchProducts(Product product) throws SystemException {
		
		try {
			return productsLocal.searchProducts(product);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "searchProducts");
		}
	}

}
